package com.kx.center.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kx.center.entity.Company;
import com.kx.center.mappers.CompanyMapper;
import com.kx.center.service.CompanyService;
import com.kx.center.util.Response;
import com.kx.center.util.SQLUtil;

/**
 * 公司服务类
 * 1. 公司管理
 * 2. 品牌管理
 * 3. 公司账户管理
 * @author acmen
 */
@Service
public class CompanyServiceImpl implements CompanyService{
	
	@Autowired
	private CompanyMapper companyMapper;
	
	/**
	 * 添加公司
	 */
	@Override
	public boolean addCompany(Company company) {
		int addStatus = companyMapper.insertCompany(company);
		if(addStatus > 0){
			return true;
		}
		return false;
	}

	/**
	 * 获取公司列表
	 */
	@Override
	public List<Company> getCompanyList(int pageNum, int count, Map<String, Object> whereMap) {
		
		String order = "id desc";
		String limitStr = pageNum * count +","+(count+1);
		
		String where = "";
		where = SQLUtil.builWhere(whereMap);
		List<Company> companyList = companyMapper.findCompanyList(where, order, limitStr);
		
		if(companyList == null){
			companyList = new ArrayList<Company>();
		}
		
		return companyList;
	}

	@Override
	public Company getCompanyById(int companyId) {
		return companyMapper.findCompanyById(companyId);
	}

	@Override
	public Company findDetail(int id) {
		return companyMapper.findDetail(id);
	}

	@Override
	public void updateCompany(Company company) {
		
		companyMapper.updateCompanyInfo(company);
	}

	@Override
	public void deleteCompanyById(int id) {
		companyMapper.deleteCompanyById(id);
	}
	
}
